<!DOCTYPE html>
<html>
	<head>
		<title>我的游记</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/plugins/jquery/jquery.min.js"></script>
		<script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/userTravels.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/dialog2/dialog.min.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            //首先我们需要获取当前页的标签
            var currentInput = $('#currentPage');
            //因为我们手机滚动之前的数据就没有了,只有当前查出来的不合理
            var arr = [];
            var pages = 1;
            var likeCount;
            function query() {
                //获取当前页
                var currentPage = currentInput.val();
                $.get("/users/" + user.id + "/travels", {currentPage: currentPage}, function (data) {
                    console.log(data);
                    pages = data.pages;
                    //把两个数组的数据合并在一起,就可以滚动了
                    $.merge(arr, data.list);
                    var json = {
                        list: arr
                    }
                    likeCount = json.list.count;
                    $('.travels').renderValues(json, {
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        }
                    });
                    $.each($(".likeCount"), function (index, ele) {
                        if ($(ele).html()=="") {
                            $(ele).html(0);
                        }
                    })
                });
                currentInput.val(parseInt(currentPage) + 1);
            }

            query();
            $(window).scroll(function () {
                if ($(document).scrollTop() + $(window).height() >= $(document).height()) {
                    var val = currentInput.val();
                    if (val <= pages) {
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '已经加载到底了!!!',
                            autoClose: 1000
                        });
                    }
                }
            });
        });

    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>

	<input type="hidden" name="currentPage" id="currentPage" value="1"/>
	<div class="container travels">
		<dl class="list" render-loop="list"><dd>
			<a data-href="editTravels.html?id="  render-key="list.id" render-fun="getHref" >
				<img render-src="list.coverUrl">
				<h6 class="title" render-html="list.title"></h6>
				<p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
					<span class="span-right">
							  <i class="fa fa-heart"></i><span>0</span>收藏
						  <i class="fa fa-thumbs-up"></i><span render-html="list.count" class="likeCount"></span>点赞</span>
				</p>
			</a>
		</dd>
		</dl>
	</div>

    </body>
</html>
